//https://www.nowcoder.com/practice/f9f78ca89ad643c99701a7142bd59f5d?tpId=13&tqId=2273171&ru=%2Fpractice%2Ffc533c45b73a41b0b44ccba763f866ef&qru=%2Fta%2Fcoding-interviews%2Fquestion-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D13%26type%3D13

#include <iostream>
#include <vector>
#include <stack>

struct ListNode {
      int val;
      struct ListNode *next;
      ListNode(int x) :
            val(x), next(NULL) {
      }
};

class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        //加入一个头节点
        ListNode* res = new ListNode(0);
        res->next = head;
        //前序节点
        ListNode* pre = res;
        //当前节点
        ListNode* cur = head;
        //遍历链表
        while(cur != NULL){
            //找到目标节点
            if(cur->val == val){
                //断开连接
                pre->next = cur->next;
                break;
            }
            pre = cur;
            cur = cur->next;
        }
        //返回去掉头节点
        return res->next;
    }
};

